#ifndef EXAMPLE_H
#define EXAMPLE_H

#include "Lboard.h"
#include "stdint.h"

#ifndef MSG_UART_ID
#define MSG_UART_ID 1
#endif

#ifndef BAUD_RATE
#define BAUD_RATE 500000
#endif

#define __DEBUG__
#ifdef __DEBUG__
    #define DBUG_SHOW(...) printf(__VA_ARGS__)  //宏打印函数定义
#else
    #define DBUG_SHOW(...)
#endif

#define MIN_IRQ_PRIORITY 1
#define MAX_IRQ_PRIORITY PLIC_MAX_PRIORITY

#define I2C_PRIORITY    (MIN_IRQ_PRIORITY + 1)
#define TIMER_PRIORITY  (MIN_IRQ_PRIORITY + 2)
#define DMAC_PRIORITY   (MIN_IRQ_PRIORITY + 8)
#define UART_PRIORITY   (MIN_IRQ_PRIORITY + 9)
#define CAN_PRIORITY    (MIN_IRQ_PRIORITY + 7)
#define RTC_PRIORITY    (MIN_IRQ_PRIORITY + 6)
#define EXT_PRIORITY    (MIN_IRQ_PRIORITY + 4)
#define SPI_PRIORITY    (MIN_IRQ_PRIORITY + 5)
#define MEMSPI_PRIORITY (MIN_IRQ_PRIORITY + 1)
#define GPIO_PRIORITY   (MIN_IRQ_PRIORITY + 1)
#define FLASH_PRIORITY  (MAX_IRQ_PRIORITY - 5)
#define USB_PRIORITY    (MAX_IRQ_PRIORITY - 1)
#define MAC_PRIORITY    (MAX_IRQ_PRIORITY - 1)
#define WDOG_PRIORITY   (MAX_IRQ_PRIORITY - 0)

__attribute__((weak)) void (*button_isr_cb)(void);

#define WAIT_UART { if (MSG_UART) while (UART_IsTxBusy(MSG_UART)); }

bool I2cInit(uint32_t frequency);
int SPI_Send(SPI_TypeDef *spi, uint8_t *txBuff, int txLen);
int SPI_SendAndRecv(SPI_TypeDef *spi, uint8_t *txBuff, int txLen, uint8_t *rxBuff, int rxLen);
void TestSpi();
void TestI2c();

//------------------------全局时钟操作---------------------------------//
void GLB_Timer_INC();
void GLB_Timer_SAVE(uint32_t time);
void GLB_Timer_RELOAD();

#endif
